package com.yunhai.support.controller;

import com.yunhai.common.dto.Ret;
import com.yunhai.support.entity.vo.*;
import com.yunhai.support.service.WechatTemplateService;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 微信公众号模板推送
 * */
@RestController
@RequestMapping("/template")
public class WechatTemplateController {

    @Resource
    private WechatTemplateService wechatTemplateService;

    @Resource
    private WxMpService wxMpService;


    @PostMapping("/deviceAlarm")
    public Ret startWechatTemplate(@RequestBody WechatTemplateVo wechatTemplateVo) throws Exception {

        wechatTemplateService.startWechatTemplate(wechatTemplateVo);
        return Ret.ok();
    }


    @PostMapping("/deviceannualCharge")
    public Ret startDeviceannualChargeWechatTemplate(@RequestBody WechatAnnualChargeTemplateVo wechatAnnualChargeTemplateVo) throws Exception {

        wechatTemplateService.startDeviceannualChargeWechatTemplate(wechatAnnualChargeTemplateVo);
        return Ret.ok();
    }

    @PostMapping("/deviceAudioAlarm")
    public Ret startWechatAudioTemplate(@RequestBody WechatAudioTemplateVo wechatAudioTemplateVo) throws Exception {
        wechatTemplateService.startWechatAudioTemplate(wechatAudioTemplateVo);
        return Ret.ok();
    }



    @PostMapping("/deviceTrunOnElectricAlarm")
    public Ret startTrunOnElectricWechatTemplate(@RequestBody WechatTurnOnTemplateVo wechatTurnOnTemplateVo) throws Exception {

        wechatTemplateService.startTrunOnElectricWechatTemplate(wechatTurnOnTemplateVo);
        return Ret.ok();
    }



    @PostMapping("/deviceTrunOutElectricAlarm")
    public Ret startTrunOutElectricWechatTemplate(@RequestBody WechatTurnOutTemplateVo wechatTurnOutTemplateVo) throws Exception {

        wechatTemplateService.startTrunOutElectricWechatTemplate(wechatTurnOutTemplateVo);
        return Ret.ok();
    }


    @PostMapping("/deviceStatus")
    public Ret startDeviceStatusTemplate(@RequestBody DeviceStatusTemplateVo deviceStatusTemplateVo) throws Exception {

        wechatTemplateService.startDeviceStatusTemplate(deviceStatusTemplateVo);
        return Ret.ok();
    }



    @GetMapping("/accesstoken")
    public Ret getAccessToken() throws Exception {
        return Ret.ok( wxMpService.getAccessToken() );
    }


}
